<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'订单列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$data=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['nickname']){
		$data['nickname like']='%'.trim($_RQ['nickname']).'%';
		$mid=pdo_getcolumn('core_members',$data,'id');
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	if(!empty($_RQ['orderno'])){
		$params['orderno']=$_RQ['orderno'];
		$return['params']['orderno']=$_RQ['orderno'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['ispay'])){
		$params['ispay']=intval($_RQ['ispay']);
		$return['params']['ispay']=$_RQ['ispay'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			//$item['detail']='/commission/list/ordersn='.$item['ordersn'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'orderno','title'=>'订单号','type'=>'string'),
			array('name'=>'fee','title'=>'订单金额','type'=>'string'),
			//array('name'=>'status','title'=>'发货状态','type'=>'radio','options'=>'status'),
			array('name'=>'ispay','title'=>'支付状态','type'=>'radio','options'=>'ispay'),
			array('name'=>'coupon_type','title'=>'券类型','type'=>'radio','options'=>'coupon_type'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
		//	array('type'=>'href','name'=>'detail','title'=>'佣金明细'),
		)),
		'search'=>array(
			array('type'=>'string','name'=>'orderno','title'=>'订单号','width'=>'15'),
			array('type'=>'string','name'=>'nickname','title'=>'购买人昵称','width'=>'15'),
			array('type'=>'select','name'=>'status','title'=>'发货状态','options'=>'status_select','width'=>'15'),
			array('type'=>'select','name'=>'ispay','title'=>'支付状态','options'=>'ispay_select','width'=>'15'),
		),
	);
	$return['htmls']=$htmls;
	
	$return['coupon_type']=array('0'=>'兑品券','1'=>'收货券');
	$return['ispay']=array('0'=>'待支付','1'=>'已支付');
	$return['isuse']=array('0'=>'待使用','1'=>'已使用');
	$return['status']=array('1'=>'待发货','2'=>'已发货','3'=>'已收货','4'=>'已完成','5'=>'已关闭');
	$return['status_select']=array(array('id'=>'1','title'=>'待发货'),array('id'=>'2','title'=>'已发货'),array('id'=>'3','title'=>'已收货'),array('id'=>'4','title'=>'已完成'),array('id'=>'5','title'=>'已关闭'));
	$return['ispay_select']=array('0'=>'待支付','1'=>'已支付');
	$return['ispay_select']=array(array('id'=>'0','title'=>'待支付'),array('id'=>'1','title'=>'已支付'));
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_sendgoods_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_sendgoods_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>